var num=''
var gtitle=''
var gauthor=''
var gtext=''
var gid=2
var gavatar=""
var util = require('../../utils/util.js')

Page({
    data: {
        list: []
    },

    GetTitle(title) {    //增加标题
        gtitle=title.detail.value
        this.setData({
            gtitle: title.detail.value
        })
    },

    GetAuthor(author) {  //增加作者
        gauthor=getApp().globalData.user.nickName
        this.setData({
            gauthor: author.detail.value
        })
    },

    GetText(text) {    //增加正文
        gtext=text.detail.value
        this.setData({
            gtext: text.detail.value
        })
    },

    Post() {    //发布
        var time = util.formatTime(new Date())
        
        gauthor=getApp().globalData.user.nickName

        var ggid=getApp().globalData.postsdata[getApp().globalData.postsdata.length-1].id + 1
        gid=ggid

        getApp().globalData.postsdata.push({
            avatar: getApp().globalData.user.avatarUrl,
            date: time,
            title: gtitle,
            author: gauthor,
            text: gtext,
            id: gid
        })
        
        wx.setStorageSync('PostsData',getApp().globalData.postsdata)//将帖子数据存入缓存

        wx.navigateTo({
            url: "../index/index",
            success: function (res) {
                var page = getCurrentPages().pop();  
                // if (page == undefined || page == null) {
                //     return; 
                // }
                page.onLoad();  
              }
        })
    }
})